<?php namespace Zmsun\XML;class SimpleXMLElementS extends \SimpleXMLElement{public function addFragment($fragment,$empty=false){if(is_string($fragment)){$rTagName=uniqid('smpRoot');if(!$fragment=@simplexml_load_string("<$rTagName>".$fragment."</$rTagName>")){return false;}}elseif(!$fragment instanceof \SimpleXMLElement){return false;}if($empty)$this[0]="";$this->pushFragment($this,$fragment);return true;}private function pushFragment(\SimpleXMLElement$dest,\SimpleXMLElement$ref){foreach($ref as$tagName=>$node){$newNode=$dest->addChild($tagName,strval($node));$attrs=$node->attributes();foreach($attrs as$attrName=>$attrVal){$newNode->addAttribute($attrName,$attrVal);}if($node->count()){$this->{__FUNCTION__}($newNode,$node->children());}}}}?>